//
//  ControlView.swift
//  xgwjinterconnection
//
//  Created by WangWeiShuo on 2025/8/13.
//

import SwiftUI

struct ControlView: View {
    var body: some View {
        
        VStack(spacing: 20){
            
            NavigationLink(){
                RadioView()
            }label: {
                ImageButton(defaultImage: "bg_radio_normal", pressedImage: "bg_radio_pressed")
                
            }
            
            NavigationLink(){
                AirConditionalView()
            }label: {
                ImageButton(defaultImage: "bg_air_normal", pressedImage: "bg_air_pressed")
                
            }
            
            //                Button(action: {
            //                    print("点击收音机")
            //                }) {
            //                    // 空标签，因为样式中已经包含了图片
            //                }
            //                .buttonStyle(ImageButtonStyle(normalIcon: "bg_radio_normal", pressedIcon: "bg_radio_pressed"))
            Spacer()
        }
        .navigationTitle("") // 隐藏默认大标题，用自定义顶部栏
        .navigationBarHidden(true)
    }
}

// 定义自定义图片按钮样式
struct ImageButtonStyle: ButtonStyle {
    let normalIcon: String
    let pressedIcon: String
    
    func makeBody(configuration: Configuration) -> some View {
        Image(configuration.isPressed ? pressedIcon: normalIcon)
            .resizable()
            .padding()
            .frame(maxWidth: .infinity,maxHeight: 200)
            .scaleEffect(configuration.isPressed ? 0.9 : 1.0)
            .animation(.spring(), value: configuration.isPressed)
    }
}

#Preview {
    ControlView()
}
